'''
Created on 2012-8-25

@author: Administrator
'''
import httplib 
import urllib,urllib2,cookielib
import Cookie  
import datetime  
import random  


class putAndDelete:
    header = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}
    
    def __init__(self):
        pass
    def put(self):
        conn = httplib.HTTPConnection("127.0.0.1",8080) 
        conn.request("PUT", "/Travel/1.txt") 
        r1 = conn.getresponse() 
        print r1.status, r1.reason ,r1.msg
        pass
    def delete(self):
        conn = httplib.HTTPConnection("127.0.0.1",8080) 
        conn.request("DELETE", "/Travel/1.txt") 
        r1 = conn.getresponse() 
        print r1.status, r1.reason ,r1.msg
    def make_cookie_header(self,cookie):
        ret = ''
        for v in cookie.values():
            ret += '%s=%s;' % (v.key, v.value)
        return ret


    def cookie(self):
        scookie="_ntes_nnid=dc4fb5e388d941736ee58df426ad0547,0; _ntes_nuid=dc4fb5e388d941736ee58df426ad0547; vjuids=-2f98b1c57.12bb523f651.0.26da76cf84e734; vjlast=1287234254.1287585858.13; USERTRACK=113.97.81.106.1287483391896449; ntes_ucc=; NTES_UFC=6110000000000011100000000000000000000000000000000000000000000000; Province=020; City=0755; P_INFO=royliaoz@126.com|1287669843|1|blog|00&21|gud&1287654699&blog#gud&440300#10|&0; NTES_SESS=mN6sV5o3Yi1oFHvg6DXifuYyz9NytbnzqfCcVshMbVZBMMmVw5c7iWrtp.loqphN7jtx0tFWuUMfZhSMzBKa.ymRAqC.hRPMhx5d5kFqXH7tdZO3cx5jChYiu; S_INFO=1287669843|0|#1&25#; NTES_PASSPORT=G_gfGY4pcEEfLKREAh8.m3hog5jSWyYhWzB.KnNPL1BZ..68zTf5Xm0lLw2_3LVa5NlOKlgmMp.q1EP0H0Gz7kF_dLxZTR_KH; NEBLOG_LOGIN=2|royliaoz@126.com|_fks_0iokmKjHBJY=; NETEASE_AUTH_USERNAME=royliaoz@126; __utma=108061393.875253878.1287586204.1287586204.1287586204.1; __utmz=108061393.1287586204.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); NETEASE_LOGIN_USERNAME=royliaoz@126.com; BLOG_FOLLOW_VIEW_TYPE=146945095:0; BLOG_LIST_VIEW_TYPE=1; NTESBLOGSI=08DB204FFBE1D776D8610D872D19163A.app-63"
        ccookie=Cookie.SimpleCookie(scookie)
        mcookie=self.make_cookie_header(ccookie)
        post_data = urllib.urlencode({"allowview":"-100"});
        header = {'Cookie':mcookie,'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}

        conn = httplib.HTTPConnection("127.0.0.1",8080) 
        conn.request("POST", "/Travel/cityInfo.action",post_data,header)
        r1 = conn.getresponse() 
        print r1.status, r1.reason ,r1.msg
        #urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
        #request = urllib2.Request("http://localhost:8080/Travel/cityInfo.action")
        #url = urlOpener.open(request)
        #page = url.read()
        #print page


if __name__ == '__main__':
   pd=putAndDelete()
   pd.cookie()